#include <QStringList>
#include "Settings.h"
#include "SimpleCrypt.h"
Settings::Settings()
{


}
QStringList Settings::AccountsList()
{
    set.beginGroup("Account");
    QStringList list = set.allKeys();
    set.endGroup();
    list = list.filter("@gmail.com");
    list = list.replaceInStrings("/password","");
    list = list.replaceInStrings("/notifications","");
    list.removeDuplicates();
    return list;
}

bool Settings::setValueForKey(QString key, QVariant value)
{
    set.setValue(key,value);
    return (getValueOfKey(key)==value);
}

QVariant Settings::getValueOfKey(QString key)
{
    return set.value(key);
}
void Settings::delKey(QString key)
{
    set.remove(key);
}

void Settings::EncryptPassword(QString email, QString password)
{

    SimpleCrypt crypto(Q_UINT64_C(0x0c2ad4a4acb9f023));
    QString encryptedPassword = crypto.encryptToString(password);
    if( SimpleCrypt::ErrorNoError == crypto.lastError() )
        setValueForKey(QString("Account/").append(email).append("/password"),encryptedPassword);

}

QString Settings::DecryptPassword(QString password)
{

    SimpleCrypt crypto(Q_UINT64_C(0x0c2ad4a4acb9f023));
    QString decryptedPassword = crypto.decryptToString(password);
    if( SimpleCrypt::ErrorNoError == crypto.lastError() )
        return decryptedPassword;
    return 0;
}

